#include<iostream>
#include<vector>
using namespace std;
const int N = 5e5 + 10;
int depth[N], father[N], sz[N], son[N];
int top[N];
vector<int>e[N];
int n, m, root;
void dfs1(int u, int fa)
{
	depth[u] = depth[fa] + 1;
	sz[u] = 1;
	father[u] = fa;
	for (int v : e[u]) {
		if (v == fa)continue;
		dfs1(v, u);
		sz[u] += sz[v];
		if (sz[son[u]] < sz[v])son[u] = v;
	}
}

void dfs2(int u, int t)
{
	top[u] = t;
	if (!son[u])return;
	dfs2(son[u], t);
	for (int v : e[u]) {
		if (v == father[u] || v == son[u])continue;
		dfs2(v, v);
	}
}

int lca(int u, int v)
{
	while (top[u] != top[v]) {
		if (depth[top[u]] < depth[top[v]])swap(u, v);
		u = father[top[u]];
	}
	return depth[u] < depth[v] ? u : v;
}
int main()
{
	cin >> n >> m >> root;
	for (int i = 0; i < n - 1; i++) {
		int u, v;
		scanf_s("%d%d", &u, &v);
		e[u].push_back(v);
		e[v].push_back(u);
	}
	dfs1(root, 0);
	dfs2(root, root);
	while (m--) {
		int u, v;
		scanf_s("%d%d", &u, &v);
		printf("%d\n", lca(u, v));
	}
	return 0;
}